/**
 * 项目配置文件
 */

const CopyWebpackPlugin = require('copy-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const appConfig = require('./src/config/appConfig.js');

module.exports = {
    //应用所在域名根目录位置
    publicPath: process.env.VUE_APP_PATH,

    //开发环境设置
    devServer: {
        host: appConfig.onlineDebug ? appConfig.onLineDomain : appConfig.localDomain,
        port: appConfig.port,
        open: true,
        hot: true,
        compress: true,

        proxy: {
            '/api': {
                target: appConfig.onlineDebug ? appConfig.onLineApiDomain : appConfig.localApiDomain,
                changeOrigin: true,
                secure: false,
                ws: true,
                pathRewrite: {
                    '^/api': ''
                }
            },
        }
    },

    //输出相关
    outputDir: process.env.VUE_APP_OUTPUTDIR,
    assetsDir: process.env.VUE_APP_STATIC,
    indexPath: 'index.html',

    //需要做es语法转义的依赖
    transpileDependencies: [],

    //是否启用生产环境map
    productionSourceMap: false,

    //webpack 自定义配置
    configureWebpack: {
        //文件加载配置
        resolve: {
            modules: [
                'src/helpers',
            ],
            extensions: ['.css', '.less', '.scss']
        },

        output: process.env.NODE_ENV === 'production' ?
            {
                filename: process.env.VUE_APP_STATIC + '/js/[name].[chunkhash].js?v=' + appConfig.sourceV,
                chunkFilename: process.env.VUE_APP_STATIC + '/js/[id].[chunkhash].js?v=' + appConfig.sourceV
            }
            :
            {
                filename: process.env.VUE_APP_STATIC + '/js/[name].js?v=' + appConfig.sourceV,
                chunkFilename: process.env.VUE_APP_STATIC + '/js/[id].js?v=' + appConfig.sourceV
            },

        plugins: process.env.NODE_ENV === 'production' ?
            [
                new MiniCssExtractPlugin({
                    filename: process.env.VUE_APP_STATIC + '/css/[name].[contenthash].css?v=' + appConfig.sourceV,
                    allChunks: true,
                }),
                new CopyWebpackPlugin([
                    {
                        from: process.env.VUE_APP_PUBLICDIR + '/' + process.env.VUE_APP_STATIC,
                        to: process.env.VUE_APP_STATIC,
                        ignore: ['.*']
                    }
                ])
            ]
            :
            [
                new CopyWebpackPlugin([
                    {
                        from: process.env.VUE_APP_PUBLICDIR + '/' + process.env.VUE_APP_STATIC,
                        to: process.env.VUE_APP_STATIC,
                        ignore: ['.*']
                    }
                ])
            ]
    },

    //css 相关配置
    css: {
        requireModuleExtension: true,
        sourceMap: true
    }
};





